package com.jxk.authservice.controller;

import com.jxk.authservice.service.UserService;
import com.jxk.common.entity.User;
import com.jxk.common.util.JwtUtils;
import com.jxk.common.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@RestController
public class ProviderTokenContrller {
    @Autowired
    UserService userService;
    @PostMapping("/user/login")
    Result login(@RequestBody User user){
        User user1 = userService.queryUser(user);
        if (!ObjectUtils.isEmpty(user1)){
             return Result.ok().data("token", JwtUtils.getJwtToken(String.valueOf(user1.getId()),user1.getUsername()));
        }
        return  Result.error();
    }
}
